package net.yxsoft.kit;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jfinal.kit.PropKit;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.StringJoiner;

public class FlashcatKit {
    //夜莺访问地址
    private static String url= PropKit.get("flashcat.url");
    //夜莺登入用户
    private static String username= PropKit.get("flashcat.username");
    //夜莺登入密码
    private static String password= PropKit.get("flashcat.password");

    /**
     * 夜莺登入
     * 返回dat(包含access_token)
     * */
    public static JsonNode flashcatLogin(){
        JSONObject jsonQuery = new JSONObject();
        jsonQuery.put("username", username);
        jsonQuery.put("password", password);
        JsonNode jsonNode = FlashcatPost(url+"/api/n9e/auth/login", jsonQuery.toJSONString(),null);
        return jsonNode;
    }

    /**
     * 夜莺查询机器列表
     * */
    public static JsonNode machineList(String authorization){
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/targets",authorization);
        return jsonNode;
    }

    /**
     * 夜莺查询数据源列表
     * */
    public static JsonNode sourceList(String authorization){
        JsonNode jsonNode = FlashcatPost(url+"/api/n9e/datasource/list","{}",authorization);
        return jsonNode;
    }
    /**
     * cpu利用率
     * @param ident 机器唯一标识
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param contrastStart 比对开始时间(时间戳)
     * @param contrastEnd 比对结束时间(时间戳)
     * @param step 时间颗粒度
     * @param datasoureId 数据源id
     * @param authorization 认证
    * */
    public static JsonNode cpuUsageSystem(String ident,Long start,Long end,Long contrastStart,Long contrastEnd,String step,String datasoureId,String authorization){
        String query = "cpu_usage_system{ident=~\""+ident+"\",cpu=\"cpu-total\"}";
        JSONObject jsonQuery = new JSONObject();
        jsonQuery.put("end", end);
        jsonQuery.put("start", start);
        jsonQuery.put("query", query);
        jsonQuery.put("step", Long.valueOf(step));
        jsonQuery.put("refId", "A");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonQuery);
        //如果有比对的时间加上比对的时间查询
        if(contrastStart!=null){
            JSONObject jsonQueryTwo = new JSONObject();
            jsonQueryTwo.put("end", contrastEnd);
            jsonQueryTwo.put("start", contrastStart);
            jsonQueryTwo.put("query", query);
            jsonQueryTwo.put("step", Long.valueOf(step));
            jsonQueryTwo.put("refId", "B");
            jsonArray.add(jsonQueryTwo);
        }
        JSONObject jsonData = new JSONObject();
        jsonData.put("queries",jsonArray);
        jsonData.put("datasource_id", Long.valueOf(datasoureId));
        JsonNode jsonNode = FlashcatPost(url+"/api/n9e/query-range-batch", jsonData.toJSONString(),authorization);
        return jsonNode;
    }

    /**
     * 内存利用率
     * @param ident 机器唯一标识
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param contrastStart 比对开始时间(时间戳)
     * @param contrastEnd 比对结束时间(时间戳)
     * @param step 时间颗粒度
     * @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode memUsedPercent(String ident,Long start,Long end,Long contrastStart,Long contrastEnd,String step,String datasoureId,String authorization){
        String query = "mem_used_percent{ident=~\""+ident+"\"}";
        JSONObject jsonQuery = new JSONObject();
        jsonQuery.put("end", end);
        jsonQuery.put("start", start);
        jsonQuery.put("query", query);
        jsonQuery.put("step", Long.valueOf(step));
        jsonQuery.put("refId", "A");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonQuery);
        //如果有比对的时间加上比对的时间查询
        if(contrastStart!=null){
            JSONObject jsonQueryTwo = new JSONObject();
            jsonQueryTwo.put("end", contrastEnd);
            jsonQueryTwo.put("start", contrastStart);
            jsonQueryTwo.put("query", query);
            jsonQueryTwo.put("step", Long.valueOf(step));
            jsonQueryTwo.put("refId", "B");
            jsonArray.add(jsonQueryTwo);
        }
        JSONObject jsonData = new JSONObject();
        jsonData.put("queries",jsonArray);
        jsonData.put("datasource_id", Long.valueOf(datasoureId));
        JsonNode jsonNode = FlashcatPost(url+"/api/n9e/query-range-batch", jsonData.toJSONString(),authorization);
        return jsonNode;
    }

    /**
     * 硬盘利用率
     * @param ident 机器唯一标识
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param contrastStart 比对开始时间(时间戳)
     * @param contrastEnd 比对结束时间(时间戳)
     * @param step 时间颗粒度
     * @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode diskUsedPercent(String ident,Long start,Long end,Long contrastStart,Long contrastEnd,String step,String datasoureId,String authorization){
        String query = "disk_used_percent{ident=~\""+ident+"\"}";
        JSONObject jsonQuery = new JSONObject();
        jsonQuery.put("end", end);
        jsonQuery.put("start", start);
        jsonQuery.put("query", query);
        jsonQuery.put("step", Long.valueOf(step));
        jsonQuery.put("refId", "A");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonQuery);
        //如果有比对的时间加上比对的时间查询
        if(contrastStart!=null){
            JSONObject jsonQueryTwo = new JSONObject();
            jsonQueryTwo.put("end", contrastEnd);
            jsonQueryTwo.put("start", contrastStart);
            jsonQueryTwo.put("query", query);
            jsonQueryTwo.put("step", Long.valueOf(step));
            jsonQueryTwo.put("refId", "B");
            jsonArray.add(jsonQueryTwo);
        }
        JSONObject jsonData = new JSONObject();
        jsonData.put("queries",jsonArray);
        jsonData.put("datasource_id", Long.valueOf(datasoureId));
        JsonNode jsonNode = FlashcatPost(url+"/api/n9e/query-range-batch", jsonData.toJSONString(),authorization);
        return jsonNode;
    }

    /**
     * 查看上行带宽
     * @param ident 机器唯一标识
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param contrastStart 比对开始时间(时间戳)
     * @param contrastEnd 比对结束时间(时间戳)
     * @param step 时间颗粒度
     * @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode netBytesSent(String ident,Long start,Long end,Long contrastStart,Long contrastEnd,String step,String datasoureId,String authorization){
        String query = "rate(net_bytes_sent{ident=~\""+ident+"\"}[1m])*8/1000";
        JSONObject jsonQuery = new JSONObject();
        jsonQuery.put("end", end);
        jsonQuery.put("start", start);
        jsonQuery.put("query", query);
        jsonQuery.put("step", Long.valueOf(step));
        jsonQuery.put("refId", "A");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonQuery);
        //如果有比对的时间加上比对的时间查询
        if(contrastStart!=null){
            JSONObject jsonQueryTwo = new JSONObject();
            jsonQueryTwo.put("end", contrastEnd);
            jsonQueryTwo.put("start", contrastStart);
            jsonQueryTwo.put("query", query);
            jsonQueryTwo.put("step", Long.valueOf(step));
            jsonQueryTwo.put("refId", "B");
            jsonArray.add(jsonQueryTwo);
        }
        JSONObject jsonData = new JSONObject();
        jsonData.put("queries",jsonArray);
        jsonData.put("datasource_id", Long.valueOf(datasoureId));
        JsonNode jsonNode = FlashcatPost(url+"/api/n9e/query-range-batch", jsonData.toJSONString(),authorization);
        return jsonNode;
    }


    /**
     * 查询区块链节点
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainJobList(String datasoureId,String authorization){
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/series?match[]=chainmaker_committer_metric_block_counter",authorization);
        return jsonNode;
    }


    /**
     * 区块链高度
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerBlockCounter(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="chainmaker_committer_metric_block_counter{chainId=~\""+chainId+"\", job=~\""+job+"\"}";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }

    /**
     * 交易池数量
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerTxPoolSize(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="chainmaker_txpool_metric_tx_pool_size{chainId=~\""+chainId+"\", job=~\""+job+"\"}";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }

    /**
     * 待打包交易数
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerTxCounter(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="chainmaker_committer_metric_tx_counter{chainId=~\""+chainId+"\", job=~\""+job+"\"}";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }

    /**
     * 区块链tps
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerTps(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="chainmaker_committer_metric_tps_gauge{chainId=~\""+chainId+"\", job=~\""+job+"\"}";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }


    /**
     *区块链查询类请求数
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerQueryRequest(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="sum by (instance, chainId) (chainmaker_rpcserver_metric_query_request_counter{chainId=~\""+chainId+"\", job=~\""+job+"\"})";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }

    /**
     *区块链交易类请求数
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerInvokeRequest(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="sum by (instance, chainId) (chainmaker_rpcserver_metric_invoke_request_counter{chainId=~\""+chainId+"\", job=~\""+job+"\"})";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }

    /**
     *平均块大小
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerAvgBlockSize(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="avg_over_time(chainmaker_committer_metric_block_size_sum{chainId=\""+chainId+"\",job=~\""+job+"\"}["+step+"s]) " +
                "/ avg_over_time(chainmaker_committer_metric_block_size_count{chainId=\""+chainId+"\",job=~\""+job+"\"}["+step+"s])";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }


    /**
     *平均出块周期
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerAvgBlockOutput(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="avg_over_time(chainmaker_committer_block_interval_seconds_sum{chainId=\""+chainId+"\",job=~\""+job+"\"}["+step+"s]) " +
                "/ avg_over_time(chainmaker_committer_block_interval_seconds_count{chainId=\""+chainId+"\",job=~\""+job+"\"}["+step+"s])";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }

    /**
     *平均Tps
     * @param chainId 链id
     * @param job 链节点
     * @param start 开始时间(时间戳)
     * @param end 结束时间(时间戳)
     * @param step 时间颗粒度
     *  @param datasoureId 数据源id
     * @param authorization 认证
     * */
    public static JsonNode chainmakerAvgTps(String chainId,String job,Long start,Long end,String step,String datasoureId,String authorization) throws UnsupportedEncodingException {
        if(start==null||end==null){
            return null;
        }
        String query="avg_over_time(chainmaker_committer_metric_tps_gauge{chainId=~\""+chainId+"\", job=~\""+job+"\"}["+step+"s])";
        String encodedQuery = URLEncoder.encode(query, "UTF-8");
        StringJoiner joiner = new StringJoiner("&");
        joiner.add("?query="+encodedQuery);
        joiner.add("start="+start);
        joiner.add("end="+end);
        joiner.add("step="+step);
        JsonNode jsonNode = FlashcatGet(url+"/api/n9e/proxy/"+datasoureId+"/api/v1/query_range"+joiner,authorization);
        return jsonNode;
    }


    /**
     * 获取当前的时间戳（北京时区）
     * earlyTime 提前的时间（毫秒）
     * */
    public static long getNowTime(Long earlyTime){
        // 获取当前时间戳（毫秒数）
        long now = System.currentTimeMillis();
        if(earlyTime!=null){
            now = now - earlyTime;
        }
        // 使用Asia/Shanghai代表北京时区
        ZoneId zone = ZoneId.of("Asia/Shanghai");
        // 将当前时间戳转换为LocalDateTime对象，并转换为北京时间
        LocalDateTime currentDateTime = LocalDateTime.ofEpochSecond(now / 1000, 0, ZoneOffset.ofHours(8));
        long timestamp = currentDateTime.atZone(zone).toEpochSecond();
        return timestamp;
    }

    /**
     * 字符串时间转换成时间戳
     * */
    public static long formatTime(String time){
        // 定义时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将字符串时间解析为 LocalDateTime 对象
        LocalDateTime datetime = LocalDateTime.parse(time, formatter);
        ZoneId zone = ZoneId.of("Asia/Shanghai"); // 使用Asia/Shanghai代表北京时区
        ZoneOffset offset = zone.getRules().getOffset(datetime);
        // 获取时间戳（秒数）
        long timestamp = datetime.toEpochSecond(offset);
        return timestamp;
    }

    /**
     * 带参数的post请求
     * @param url
     * @param authorization
     * @return String
     */
    public static JsonNode FlashcatGet(String url,String authorization) {
        // 创建Httpclient对象
        CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setConnectTimeout(3000) //连接超时时间
                        .setSocketTimeout(3000) //读取超时时间
                        .setConnectionRequestTimeout(3000) //请求超时时间
                        .build())
                .build();
        CloseableHttpResponse response = null;
        JsonNode jsonNode =null;
        try {
            // 创建Http get请求
            HttpGet httpGet = new HttpGet(url);
            //认证不为空，则加上认证信息
            if(StringUtils.isNotBlank(authorization)){
                httpGet.setHeader("Authorization","Bearer "+authorization);
            }
            // 执行http请求
            response = httpClient.execute(httpGet);
            String resultString = EntityUtils.toString(response.getEntity(), "utf-8");
            if("unauthorized".equals(resultString)){//认证失败
                return null;
            }
            // 将字符串转换为JSON对象
            ObjectMapper objectMapper = new ObjectMapper();
            jsonNode = objectMapper.readValue(resultString, JsonNode.class);
            response.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonNode;
    }

    /**
     * 带参数的post请求
     * @param url
     * @param param
     * @param authorization
     * @return String
     */
    public static JsonNode FlashcatPost(String url,String param,String authorization) {
        // 创建Httpclient对象
        CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setConnectTimeout(3000) //连接超时时间
                        .setSocketTimeout(3000) //读取超时时间
                        .setConnectionRequestTimeout(3000) //请求超时时间
                        .build())
                .build();
        CloseableHttpResponse response = null;
        JsonNode jsonNode =null;
        try {
            // 创建Http Post请求
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Accept-Encoding","gzip,deflate,br");
            httpPost.setHeader("Content-Type","charset=utf-8");
            //认证不为空，则加上认证信息
            if(StringUtils.isNotBlank(authorization)){
                httpPost.setHeader("Authorization","Bearer "+authorization);
            }
            // 创建参数列表
            if (param != null) {
                StringEntity postingString = new StringEntity(param,"utf-8");
                httpPost.setEntity(postingString);
            }
            // 执行http请求
            response = httpClient.execute(httpPost);
            String resultString = EntityUtils.toString(response.getEntity(), "utf-8");
            if("unauthorized".equals(resultString)){//认证失败
                return null;
            }
            // 将字符串转换为JSON对象
            ObjectMapper objectMapper = new ObjectMapper();
            jsonNode = objectMapper.readValue(resultString, JsonNode.class);
            response.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonNode;
    }

    public static void main(String[] args) {
        String query = "cpu_usage_idle{ident=~\"iZ2ze4yceifsroegny59e5Z\",cpu=\"cpu-total\"}";
        JSONObject jsonQuery = new JSONObject();
        jsonQuery.put("end", 1700821888);
        jsonQuery.put("start", 1700818275);
        jsonQuery.put("query", query);
        jsonQuery.put("step", 15);
        jsonQuery.put("refId", "A");
        JSONObject jsonData = new JSONObject();
        jsonData.put("queries", new JSONObject[] { jsonQuery });
        jsonData.put("datasource_id", 3);

        JsonNode jsonNode = FlashcatPost("http://39.107.234.33:17000/api/n9e/auth/login", "{\"username\": \"root\", \"password\": \"root.2020\"}",null);
        System.out.println(jsonNode);
        System.out.println(jsonNode.get("dat").get("access_token"));
        JsonNode jsonNode2 = FlashcatPost("http://39.107.234.33:17000/api/n9e/query-range-batch", jsonData.toJSONString(),jsonNode.get("dat").get("access_token").toString());
        System.out.println(jsonNode2);
        System.out.println(jsonNode2.get("err"));
        long s=1700818275;
        long e=1700821888;
        JsonNode jsonNode1 = cpuUsageSystem("iZ2ze4yceifsroegny59e5Z", s, e, s, e, "15", "3", jsonNode.get("dat").get("access_token").toString());
        System.out.println(jsonNode1);
    }
}
